/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jobportal.college;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.*;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import jobportal.Dbconn;

/**
 *
 * @author project
 */
public class EditProfile1 extends HttpServlet {

    /**
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doPost(request, response);
    }

    /**
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        RequestDispatcher rd;
        Connection con;
        Statement st;
        ResultSet rs;
        HttpSession session = request.getSession();
        String error = "";
        boolean flag = true;
       String dest="editprofile.jsp";
        if(session.getAttribute("role")!=null&&session.getAttribute("role").equals("admin"))
            dest="../admin/manage_cllg.jsp";
       
        String clgid, tponame, tpoemail, clgname, address, state, city, clgprofile, contact, fax, mobile, uname, url, sql;
        PrintWriter out = response.getWriter();
        try {
            con = Dbconn.getConn();
            st = con.createStatement();

            clgid = request.getParameter("clgid");
            tponame = request.getParameter("tponame");
            tpoemail = request.getParameter("tpoemail");
            clgname = request.getParameter("clgname");
            address = request.getParameter("address");
            state = request.getParameter("state");
            city = request.getParameter("city");
            clgprofile = request.getParameter("clgprofile");
            contact = request.getParameter("contact");
            fax = request.getParameter("fax");
            mobile = request.getParameter("mobile");
            uname = request.getParameter("uname");
            url = request.getParameter("url");
            sql = "update college set tponame=?,tpoemail=?,clgname=?,address=?,state=?,city=?,clgprofile=?,contact=?,fax=?,mobile=?,uname=?,url=? where clgid='" + clgid + "'";
            PreparedStatement ps = con.prepareStatement(sql);
            ps.setString(1, tponame);
            ps.setString(2, tpoemail);
            ps.setString(3, clgname);
            ps.setString(4, address);
            ps.setString(5, state);
            ps.setString(6, city);
            ps.setString(7, clgprofile);
            ps.setString(8, contact);
            ps.setString(9, fax);
            ps.setString(10, mobile);
            ps.setString(11, uname);
            ps.setString(12, url);
            if (ps.executeUpdate() > 0) {
                request.setAttribute("status", "profile successfully updated");
                response.sendRedirect(dest);
            } else {
                request.setAttribute("status", "Updated failed");
                response.sendRedirect(dest);
            }

        } catch (Exception e) {
            out.println(e);
            response.sendRedirect(dest);
            request.setAttribute("status", "Updated failed,Exception" + e);
            // rd.forward(request, response);

        }

    }
}
